package com.deer.wms.base.system.web.box;

import com.deer.wms.base.system.model.SluggishOverdueDto;
import com.deer.wms.base.system.model.box.BoxItemCriteria;
import com.deer.wms.base.system.model.box.BoxItemDto;
import com.deer.wms.base.system.service.box.IBoxItemService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/boxItem/BoxItemSoldOut")
public class BoxItemSoldOutController extends BaseController {
    @Autowired
    private IBoxItemService boxItemService;//物料库存

    private String prefix = "in/boxItem";

    @RequiresPermissions("BoxItemSoldOut:view")
    @GetMapping("/page")
    public String boxItem()
    {
        return prefix + "/BoxItemSoldOut";
    }

    @PostMapping("/findList")
    @ResponseBody
    public TableDataInfo findList(BoxItemCriteria boxItemCriteria)
    {
        List<BoxItemDto> list = new ArrayList<>();
        startPage();
        List<BoxItemDto> boxItemDtoInMain = boxItemService.getBoxItemDtoInMain(boxItemCriteria);
//        for (BoxItemDto boxItemDto : boxItemDtoInMain) {
//            Integer quantity = boxItemDto.getQuantity();
//            Integer warn = boxItemDto.getWarn();
//            if(quantity<=warn){
//                list.add(boxItemDto);
//            }
//        }
        return getDataTable(list);
    }

    /**
     * 断档报表导出
     * @param boxItemCriteria
     * @return
     */
    @RequiresPermissions("BoxItemSoldOut:export")
    @PostMapping("export")
    @ResponseBody
    public AjaxResult export(BoxItemCriteria boxItemCriteria){
        List<BoxItemDto> list = new ArrayList<>();
        ExcelUtil<BoxItemDto> util = new ExcelUtil<BoxItemDto>(BoxItemDto.class);
        List<BoxItemDto> boxItemDtoList = boxItemService.getBoxItemDtoInMain(boxItemCriteria);
        for (BoxItemDto boxItemDto: boxItemDtoList) {
            //Integer quantity = boxItemDto.getQuantity();
            //Integer warn = boxItemDto.getWarn();
//            if(quantity<=warn){
//                list.add(boxItemDto);
//            }
        }
        return util.exportExcel(list, "断档报表");
    }

}
